package com.pat.java.base.event;

import java.applet.Applet;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

public class UseItemEvent extends Applet implements ItemListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	Checkbox cDisp;
	Button btnDisp;
	Choice cFont;

	public void init() {
		cDisp = new Checkbox("红色");
		btnDisp = new Button("颜色显示");
		cFont = new Choice();
		cFont.add("10");
		cFont.add("12");
		cFont.add("14");

		cDisp.addItemListener(this);

		cFont.addItemListener(this);
		add(cDisp);
		add(cFont);
		add(btnDisp);
	}

	public void itemStateChanged(ItemEvent e) {
		Checkbox temp;
		Choice temp2;
		Font oldF;

		if (e.getItemSelectable() instanceof Checkbox) {

			temp = (Checkbox) (e.getItemSelectable());

			if (temp.getState())
				btnDisp.setBackground(Color.red);
			else
				btnDisp.setBackground(Color.blue);
		}

		if (e.getItemSelectable() instanceof Choice) {
			oldF = btnDisp.getFont();

			temp2 = (Choice) (e.getItemSelectable());
			String s = temp2.getSelectedItem();

			btnDisp.setFont(new Font(oldF.getName(), oldF.getStyle(), Integer
					.parseInt(s)));
		}
	}
}
